<?php

class Crb_Controller extends Zend_Controller_Action
{
    protected $logger;
	protected $user;
	protected $request;
	protected $hierarchy;
	
	public function preDispatch()
	{
		if ( $this->getRequest()->isXmlHttpRequest() )
		{
		    $this->_helper->layout()->disableLayout();
//			$this->_helper->viewRenderer->setNoRender(true);
		}
        
        $writer = new Zend_Log_Writer_Stream(APPLICATION_ROOT . '/logs/main.log');
        $this->logger = new Zend_Log($writer);
	}

	
    public function init()
    {
		$this->initView();
		$this->view->baseUrl = $this->_request->getBaseUrl();
    }
    
	public function Log($Message,$Level)
	{
		$this->logger->log($Message, $Level);
	}

    public function DebugLog($Message,$Dumping = '')
    {
        $this->logger->log($Message . print_r($Dumping,1),Zend_Log::DEBUG );
    }
	
	public function getUser()
	{
		Zend_Session::start();
		$namespace = new Zend_Session_Namespace('Zend_Auth');
		$auth = Zend_Auth::getInstance();
		if (!$auth->hasIdentity())
		if ($namespace->storage)
		{
			$user = array();
			$user['id'] = $namespace->storage->id;
			$user['username'] = $namespace->storage->username;
			$user['name'] = $namespace->storage->name;
			$user['role'] = $namespace->storage->role;
			return $user;
		}
		else
		{
			return array('id'=>'0','username'=>'guest','name'=>'guest','role'=>'guest');
		}
		
	}
	
	public function NotFound()
	{
			$this->view->Message = 'Not found';
			$this->_redirect('error/fof');
			return ;
	} 
	

    
    protected function disableLayout()
    {
        $this->_helper->layout->disableLayout();
    }

    protected function setNoRender()
    {
        $this->_helper->viewRenderer->setNoRender();
    }
}

